/*
 * findSumPath.cpp
 *
 *  Created on: Jul 19, 2012
 *      Author: jh238d
 */
#include "BSTNode.h"
#include <iostream>
using namespace std;

void find_sum(BSTNode* node, int sum, int path[], int level)
{
    if(node == NULL)
        return;

    path[level] = node->data;
    int s = 0;
    for(int i = level; i >=0; i--){
        s+=path[i];
        if(s==sum){
            for(int j= i; j <= level; j++)
                cout<<path[j]<<" ";
           cout << endl;
        }
    }
    find_sum(node->left, sum, path, level+1);
    find_sum(node->right, sum, path, level+1);

    path[level] = 0;
}

int depth(BSTNode *node){
    if(node==NULL) return 0;
    return 1+ max(depth(node->left), depth(node->right));
}

void find_sum(BSTNode *node, int sum){
    int d = depth(node);
    int path[d];
    for(int i=0; i<d; i++)
    	path[i] = 0;
    find_sum(node, sum, path, 0);
}

